package com.jhd.fuzhou.view.task;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.jhd.fuzhou.view.login.BaseActivity;
import com.jhd.fuzhou.R;
import com.jhd.fuzhou.util.StringShow;
import com.jhd.fuzhou.vo.QuestionBankOptionVo;
import com.jhd.fuzhou.vo.SupervisionInspectionContentVo;
import com.jhd.fuzhou.vo.SupervisionInspectionVo;

import java.util.List;

import butterknife.BindView;

/*抽查报告*/
public class RandomCheckActivity extends BaseActivity {

    private SupervisionInspectionVo supervisionInspectionVo;
    List<SupervisionInspectionContentVo> supervisionInspectionContentVoList;
    @BindView(R.id.rv_check_result)RecyclerView rv_check_result;
    @BindView(R.id.tv_check_record)TextView tv_check_record;//检查记录
    @BindView(R.id.tv_supervision)TextView tv_supervision;//监督意见
    private Context context=this;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_random_check);
    }

    @Override
    protected void processLogic() {
        onBack();
        String data=getIntent().getStringExtra("data");
        supervisionInspectionVo= JSON.parseObject(data, SupervisionInspectionVo.class);
        supervisionInspectionContentVoList=supervisionInspectionVo.getDoubleRandomInspectionContentList();
        tv_check_record.setText(StringShow.showStr(supervisionInspectionVo.getInspectRecords()));
        tv_supervision.setText(StringShow.showStr(supervisionInspectionVo.getSupervisionOpinions()));
        if(supervisionInspectionContentVoList!=null){
            LinearLayoutManager layoutManage = new LinearLayoutManager(context);
            rv_check_result.setLayoutManager(layoutManage);
            DoubleCheckAdapter adapter=new DoubleCheckAdapter(supervisionInspectionContentVoList);
            rv_check_result.setAdapter(adapter);
        }
    }
    public class DoubleCheckAdapter extends RecyclerView.Adapter<DoubleCheckAdapter.ViewHolder> {
        private List<SupervisionInspectionContentVo> supervisionInspectionContentVoList;

        public DoubleCheckAdapter(List<SupervisionInspectionContentVo> supervisionInspectionContentVoList) {
            this.supervisionInspectionContentVoList = supervisionInspectionContentVoList;
        }

        @NonNull
        @Override
        public DoubleCheckAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_question_tree_4, parent, false);
            DoubleCheckAdapter.ViewHolder viewHolder = new DoubleCheckAdapter.ViewHolder(itemView);
            return viewHolder;
        }
        @Override
        public void onBindViewHolder(@NonNull DoubleCheckAdapter.ViewHolder holder, int position) {
            holder.tv_question.setText(supervisionInspectionContentVoList.get(position).getQuestionBankName());
            List<QuestionBankOptionVo> questionBankOptionVos = supervisionInspectionContentVoList.get(position).getQuestionBankOptionVoList();
            if(questionBankOptionVos!=null){
                if(supervisionInspectionContentVoList.get(position).getQuestionBankOptionId()!=null){//如果已经检查过
                    for (QuestionBankOptionVo questionBankOptionVo : questionBankOptionVos) {
                        if(supervisionInspectionContentVoList.get(position).getQuestionBankOptionId().equals(questionBankOptionVo.getId())){
                            holder.tv_answer.setText(questionBankOptionVo.getOptionName());
                        }
                    }
                }
            }
        }

        @Override
        public int getItemCount() {
            return supervisionInspectionContentVoList.size();
        }
        class ViewHolder extends RecyclerView.ViewHolder {
            TextView tv_question,tv_answer;
            public ViewHolder(View itemView) {
                super(itemView);
                this.tv_question = itemView.findViewById(R.id.tv_question);
                this.tv_answer = itemView.findViewById(R.id.tv_answer);
            }
        }
    }

}